package com.lsl.test1;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import org.junit.Test;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author lishuailong
 * @create 2020-07-10 17:39
 */
public class URLtest1 {
    @Test
    public void test1() throws IOException {
        URL url = new URL("http://localhost:8111/lsl/abc.png");
        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
        urlConnection.connect();
        InputStream inputStream = urlConnection.getInputStream();
        BufferedOutputStream outputStream = FileUtil.getOutputStream("C:\\Users\\admin\\Pictures\\img\\abc.png");
        IoUtil.copy(inputStream,outputStream);

        IoUtil.close(outputStream);
        IoUtil.close(inputStream);
        urlConnection.disconnect();
    }
}
